﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.Runtime.Serialization;

namespace GalaxyZoo.Client.Model
{
    [DataContract]
    public abstract class AbstractGalaxyZooObject
    {
        protected DateTime? ToDateTime(string value)
        {
            if (string.IsNullOrEmpty(value))
                return null;
            else
            {
                if (value.EndsWith(" UTC"))
                    value = value.Substring(0, value.Length - 4);
                return DateTime.ParseExact(value, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture).ToLocalTime();
            }
        }

        protected string FromDateTime(DateTime? value)
        {
            if (value == null)
                return null;
            else
                return value.Value.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss") + " UTC";
        }
    }
}
